package cn.e_eap.esite.manager.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import cn.e_eap.esite.bean.Company;
import cn.e_eap.esite.manager.BaseManager;
import cn.e_eap.esite.manager.CompanyManager;
import cn.e_eap.esite.web.form.PagerForm;

@Component("comManager")
public class CompanyManagerImpl extends BaseManager<Company> implements
		CompanyManager {

	@Override
	public void delete(String ids) {
		if(ids == null || ids.length()<1) {
			return;
		}
		super.removeByIds(Company.class, ids);
	}

	@Override
	public List<Company> find(Company condition, PagerForm pf) {
		StringBuilder con = new StringBuilder();
		if(condition == null) {
			return super.getPageModel(Company.class, pf);
		}
		if(condition.getName() != null && condition.getName().length()>0){
			con.append(" and @.name like '%" ).append(condition.getName()).append("%'");			
		}
		if(condition.getSn() != null && condition.getSn().length()>0) {
			con.append(" and @.sn like '%").append(condition.getSn()).append("%'");
		}
		return super.getPageModel(Company.class, con.toString(),pf);
	}

	@Override
	public Company findById(int id) {
		return getHibernateTemplate().get(Company.class, id);
	}

	@Override
	public Company findBySn(String sn) {
		return super.findUnique(Company.class, " where sn='"+sn+"'");
	}

	@Override
	public Company findByName(String name) {
		return super.findUnique(Company.class, " where sn='"+name+"'");
	}

}
